<template>
    <div>
            <table class="table table-bordered">
                <tbody>
                    <tr>
                        <td>会员编号</td>
                        <td>
                            <input type="text" v-model="list.userCode" disabled>
                        </td>
                    </tr>
                    <tr>
                        <td>手机号</td>
                        <td>
                            <input type="text" v-model="list.phone" maxlength="11">
                        </td>
                    </tr>
                    <tr>
                        <td>会员名</td>
                        <td>
                            <input type="text" v-model="list.userName">
                        </td>
                    </tr>
                    <tr>
                        <td>身份证</td>
                        <td>
                            <input type="text" v-model="list.card" maxlength="18">
                        </td>
                    </tr>
                    <tr>
                        <td>会员等级</td>
                        <td>
                            <select v-model="list.levelId">
                                <option value="">请选择会员等级</option>
                                <option :value="item.id" v-for="item in data.list" >{{ item.levelName }}</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>性别</td>
                        <td>
                            <input type="radio" value="1"  v-model="list.sex">男
                            <input type="radio" value="2"  v-model="list.sex">女
                        </td>
                    </tr>
                    <tr>
                        <td>生日</td>
                        <td>
                           
                            <input type="date"  v-model="list.birthday">
                        </td>
                    </tr>
                    <tr>
                        <td>积分</td>
                        <td>
                            <input type="text"  v-model="list.jiFen">
                        </td>
                    </tr>
                    <tr>
                        <td>余额</td>
                        <td>
                            <input type="text"  v-model="list.money">
                        </td>
                    </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-primary" @click="ok">
                    </td>
                </tr>

                </tbody>
            </table>
    </div>
</template>

<script setup lang="ts">

import{ref,reactive,onMounted} from 'vue'
import axios from 'axios';
import {useRouter}from 'vue-router'
import { idText } from 'typescript';
import moment from 'moment';

onMounted(()=>{
    levelshow();
})

var num=Math.random().toString().substring(2,5);

let list=reactive({
  
  "userCode": moment(new Date()).format("YYYYMMDD")+num ,
  "phone": "",
  "userName": "",
  "card": "",
  "levelId": '',
  "sex": 1,
  "jiFen": '',
  "money": '',
  "birthday": "",

})

const ok=()=>{




    axios({
        method:'post',
        url:'/api/Member/UserAdd',
        data:list,
    })
    .then(res=>{
        console.log(res);
        if(res.data>0){
            alert("添加成功");
        }
        else{
            alert("添加失败");
        }
    })
    .catch(err=>{
        console.log(err);
    })
}











let data:any=reactive({
    list:[]
})

const levelshow=()=>{
    axios({
        method:'get',
        url:'/api/Member/GetUserLevels',

    })
    .then(res=>{
        console.log(res);
        data.list=res.data;

    })
    .catch(err=>{
        console.log(err);
    })
}


</script>

<style scoped>

</style>